package rifl.meres4.ui.tracker;

import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTrackerCustomizer;

import rifl.meres4.release.step.IRepairStep;
import rifl.meres4.ui.WorkflowUI;

public class RepairStepServiceTrackerCustomizer implements ServiceTrackerCustomizer<IRepairStep, Object> {

	private final WorkflowUI ui;
	private final BundleContext context;
	
	public RepairStepServiceTrackerCustomizer(BundleContext context, WorkflowUI ui)
	{
		this.context = context;
		this.ui= ui;
	}
	
	@Override
	public Object addingService(ServiceReference<IRepairStep> reference) {
		IRepairStep service = context.getService(reference);
		if (ui != null) {
			ui.setRepairStep(service);
		}
		return service;
	}

	@Override
	public void modifiedService(ServiceReference<IRepairStep> reference,
			Object service) {		
		
	}

	@Override
	public void removedService(ServiceReference<IRepairStep> reference,
			Object service) {
		if (ui != null) {
			ui.unsetRepairStep((IRepairStep) service);
		}
		
	}

}